//! This module contains functionality to simulate a subnet's
/// network, RTT and Packet Loss, during system tests.
use super::{
    super::{driver::test_env_api::SshSession, util::get_config},
    test_env_api::{IcNodeContainer, SubnetSnapshot},
};
use std::{time::Duration, vec::Vec};

pub trait SimulateNetwork<NetworkSettings> {
    fn apply_network_settings(&self, network_settings: NetworkSettings);
}

impl SimulateNetwork<ProductionSubnetTopology> for SubnetSnapshot {
    fn apply_network_settings(&self, network_settings: ProductionSubnetTopology) {
        let nodes: Vec<_> = self.nodes().collect();

        assert_eq!(
            nodes.len(),
            network_settings.subnet_size(),
            "Subnet size must match the size of the simulated topology."
        );

        let subnet_size = network_settings.subnet_size();
        let mut tc_commands = Vec::<String>::with_capacity(subnet_size);

        let packet_loss = network_settings.packet_loss();
        let rtt = network_settings.rtt();

        for source_node in 0..subnet_size {
            let mut tc_command =
                String::from("sudo tc qdisc del dev enp1s0 root 2> /dev/null || true \n");
            tc_command.push_str("sudo tc qdisc add dev enp1s0 root handle 1: htb \n");
            tc_command.push_str(
                "sudo tc class add dev enp1s0 parent 1: classid 1:1 htb rate 2000Mbps \n",
            );

            for destination_node in 0..subnet_size {
                if source_node == destination_node {
                    continue;
                }
                let destination_ip = nodes[destination_node].get_ip_addr();
                // tc class id start at 1 and we already defined one above so we need to start from 2..
                let tc_class_id = destination_node + 2;
                tc_command.push_str(&format!(
                    "sudo tc class add dev enp1s0 parent 1:1 classid 1:{tc_class_id} htb rate 2000Mbps \n",
                ));
                tc_command.push_str(&format!(
                        "sudo tc qdisc add dev enp1s0 handle {}: parent 1:{} netem limit 10000000 loss {:.3}% delay {}ms \n",
                        tc_class_id,
                        tc_class_id,
                        packet_loss[(subnet_size-1) * source_node + destination_node].2 * 100.0,
                        (rtt[(subnet_size-1) * source_node + destination_node].2 * 1000.0 / 2.0) as u64
                    ));
                tc_command.push_str(&format!("sudo tc filter add dev enp1s0 protocol ipv6 parent 1: pref {tc_class_id} u32 match ip6 dst {destination_ip} flowid 1:{tc_class_id} \n" ));
            }
            tc_command.push_str(
                "sudo tc class add dev enp1s0 parent 1:1 classid 1:999 htb rate 2000Mbps \n",
            );
            tc_command.push_str(
                "sudo tc qdisc add dev enp1s0 parent 1:999 handle 999: netem limit 10000000 \n",
            );
            tc_command.push_str("sudo tc filter add dev enp1s0 protocol ipv6 parent 1: pref 999 u32 match ip6 dst ::/0 flowid 1:999 \n");
            tc_commands.push(tc_command);
        }

        nodes.iter().enumerate().for_each(|(idx, node)| {
            let session = node
                .block_on_ssh_session()
                .expect("Failed to ssh into node");
            node.block_on_bash_script_from_session(&session, &tc_commands[idx])
                .expect("Failed to execute bash script from session");
        });
    }
}

impl SimulateNetwork<FixedNetworkSimulation> for SubnetSnapshot {
    fn apply_network_settings(&self, network_settings: FixedNetworkSimulation) {
        let nodes: Vec<_> = self.nodes().collect();

        const DEVICE_NAME: &str = "enp1s0"; // network interface name

        let cfg = get_config();
        let p2p_listen_port = cfg.transport.unwrap().listening_port;

        let bandwidth_mbit_per_sec = network_settings
            .bandwidth_mbit_per_sec
            .unwrap_or(100_000_000);
        let latency_ms = network_settings.latency.map(|d| d.as_millis()).unwrap_or(0);

        let packet_loss = network_settings.packet_loss.unwrap_or(0.0);
        assert!(
            (0.0..=1.0).contains(&packet_loss),
            "Packet loss must be between 0.0 and 1.0"
        );

        let packet_loss_percentage = format!("{packet_loss:.3}");
        let command = format!(
            r#"set -euo pipefail
sudo tc qdisc del dev {DEVICE_NAME} root 2> /dev/null || true
sudo tc qdisc add dev {DEVICE_NAME} root handle 1: htb default 10
sudo tc class add dev {DEVICE_NAME} parent 1: classid 1:10 htb rate {bandwidth_mbit_per_sec}mbit ceil {bandwidth_mbit_per_sec}mbit
sudo tc qdisc add dev {DEVICE_NAME} parent 1:10 handle 10: netem delay {latency_ms}ms loss {packet_loss_percentage}% limit 10000000
sudo tc filter add dev {DEVICE_NAME} parent 1: protocol ipv6 prio 1 u32 match ip6 dport {p2p_listen_port} 0xFFFF flowid 1:10
sudo tc qdisc show dev {DEVICE_NAME}
"#,
        );

        nodes.iter().for_each(|node| {
            let session = node
                .block_on_ssh_session()
                .expect("Failed to ssh into node");
            node.block_on_bash_script_from_session(&session, &command)
                .expect("Failed to execute bash script from session");
        });
    }
}

#[derive(Clone, Debug, Default)]
pub struct FixedNetworkSimulation {
    packet_loss: Option<f64>,
    latency: Option<Duration>,
    bandwidth_mbit_per_sec: Option<u32>,
}

impl FixedNetworkSimulation {
    pub const fn new() -> Self {
        Self {
            packet_loss: None,
            latency: None,
            bandwidth_mbit_per_sec: None,
        }
    }

    /// Sets the packet loss in each direction in decimal form (0.0 to 1.0).
    pub const fn with_packet_loss(self, packet_loss: f64) -> Self {
        Self {
            packet_loss: Some(packet_loss),
            ..self
        }
    }

    pub const fn with_latency(self, latency: Duration) -> Self {
        Self {
            latency: Some(latency),
            ..self
        }
    }

    pub const fn with_bandwidth(self, bandwidth_mbit_per_sec: u32) -> Self {
        Self {
            bandwidth_mbit_per_sec: Some(bandwidth_mbit_per_sec),
            ..self
        }
    }
}

#[derive(Clone, Debug)]
pub enum ProductionSubnetTopology {
    LHG73,
    /// Canary subnet
    IO67,
    /// Internet Identity Subnet
    UZR34,
}

impl ProductionSubnetTopology {
    fn rtt(&self) -> Vec<(u64, u64, f64)> {
        match self {
            ProductionSubnetTopology::LHG73 => LHG_73_RTT.to_vec(),
            ProductionSubnetTopology::IO67 => IO67_RTT.to_vec(),
            ProductionSubnetTopology::UZR34 => UZR_34_RTT.to_vec(),
        }
    }

    fn packet_loss(&self) -> Vec<(u64, u64, f64)> {
        match self {
            ProductionSubnetTopology::LHG73 => LHG73_PACKET_LOSS.to_vec(),
            ProductionSubnetTopology::IO67 => IO67_PACKET_LOSS.to_vec(),
            ProductionSubnetTopology::UZR34 => UZR_34_PACKET_LOSS.to_vec(),
        }
    }

    fn subnet_size(&self) -> usize {
        match self {
            ProductionSubnetTopology::LHG73 => 13,
            ProductionSubnetTopology::IO67 => 13,
            ProductionSubnetTopology::UZR34 => 28,
        }
    }
}

/// Query:
/// https://victoria.ch1-obs1.dfinity.network/select/0/vmui/#/?g0.expr=sum+by+%28ic_node%2Cpeer%29+%28quic_transport_quinn_path_rtt_seconds%7Bic_subnet%3D%22uzr34-akd3s-xrdag-3ql62-ocgoh-ld2ao-tamcv-54e7j-krwgb-2gm4z-oqe%22%7D%29&g0.range_input=21h24m51s870ms&g0.end_input=2024-08-20T08%3A22%3A07&g0.relative_time=none&g0.tenantID=0
pub static UZR_34_RTT: [(u64, u64, f64); 756] = [
    (1, 2, 0.15598),
    (1, 3, 0.37478),
    (1, 4, 0.13583),
    (1, 5, 0.26419),
    (1, 6, 0.2685),
    (1, 7, 0.15921),
    (1, 8, 0.07969),
    (1, 9, 0.20214),
    (1, 10, 0.41222),
    (1, 11, 0.15609),
    (1, 12, 0.23028),
    (1, 13, 0.205),
    (1, 14, 0.26206),
    (1, 15, 0.17735),
    (1, 16, 0.25761),
    (1, 17, 0.29715),
    (1, 18, 0.19226),
    (1, 19, 0.15543),
    (1, 20, 0.36432),
    (1, 21, 0.14284),
    (1, 22, 0.05377),
    (1, 23, 0.14463),
    (1, 24, 0.25803),
    (1, 25, 0.24942),
    (1, 26, 0.17277),
    (1, 27, 0.15197),
    (1, 28, 0.17169),
    (2, 1, 0.1558),
    (2, 3, 0.18167),
    (2, 4, 0.24428),
    (2, 5, 0.1322),
    (2, 6, 0.13709),
    (2, 7, 0.01866),
    (2, 8, 0.23824),
    (2, 9, 0.06627),
    (2, 10, 0.23563),
    (2, 11, 0.02084),
    (2, 12, 0.11739),
    (2, 13, 0.04274),
    (2, 14, 0.19052),
    (2, 15, 0.27049),
    (2, 16, 0.09998),
    (2, 17, 0.17725),
    (2, 18, 0.07601),
    (2, 19, 0.02554),
    (2, 20, 0.1687),
    (2, 21, 0.03541),
    (2, 22, 0.19079),
    (2, 23, 0.01521),
    (2, 24, 0.15494),
    (2, 25, 0.11967),
    (2, 26, 0.03282),
    (2, 27, 0.00982),
    (2, 28, 0.26739),
    (3, 1, 0.37482),
    (3, 2, 0.18166),
    (3, 4, 0.22102),
    (3, 5, 0.10883),
    (3, 6, 0.10923),
    (3, 7, 0.18799),
    (3, 8, 0.30704),
    (3, 9, 0.23476),
    (3, 10, 0.10802),
    (3, 11, 0.17426),
    (3, 12, 0.07633),
    (3, 13, 0.18028),
    (3, 14, 0.26706),
    (3, 15, 0.2572),
    (3, 16, 0.10358),
    (3, 17, 0.29476),
    (3, 18, 0.22275),
    (3, 19, 0.17826),
    (3, 20, 0.08183),
    (3, 21, 0.18932),
    (3, 22, 0.32744),
    (3, 23, 0.16661),
    (3, 24, 0.1332),
    (3, 25, 0.07369),
    (3, 26, 0.19568),
    (3, 27, 0.19236),
    (3, 28, 0.27564),
    (4, 1, 0.13592),
    (4, 2, 0.24435),
    (4, 3, 0.22078),
    (4, 5, 0.14195),
    (4, 6, 0.15366),
    (4, 7, 0.25079),
    (4, 8, 0.18394),
    (4, 9, 0.29446),
    (4, 10, 0.29284),
    (4, 11, 0.22095),
    (4, 12, 0.14995),
    (4, 13, 0.25318),
    (4, 14, 0.04908),
    (4, 15, 0.13845),
    (4, 16, 0.15395),
    (4, 17, 0.26367),
    (4, 18, 0.34179),
    (4, 19, 0.22368),
    (4, 20, 0.21611),
    (4, 21, 0.25414),
    (4, 22, 0.14264),
    (4, 23, 0.22814),
    (4, 24, 0.10131),
    (4, 25, 0.14685),
    (4, 26, 0.24916),
    (4, 27, 0.25928),
    (4, 28, 0.12766),
    (5, 1, 0.26404),
    (5, 2, 0.13239),
    (5, 3, 0.10881),
    (5, 4, 0.14208),
    (5, 6, 0.04367),
    (5, 7, 0.12043),
    (5, 8, 0.22722),
    (5, 9, 0.1691),
    (5, 10, 0.15739),
    (5, 11, 0.11531),
    (5, 12, 0.01885),
    (5, 13, 0.12477),
    (5, 14, 0.18759),
    (5, 15, 0.18194),
    (5, 16, 0.04194),
    (5, 17, 0.23972),
    (5, 18, 0.17445),
    (5, 19, 0.11108),
    (5, 20, 0.09101),
    (5, 21, 0.10918),
    (5, 22, 0.28342),
    (5, 23, 0.10299),
    (5, 24, 0.04957),
    (5, 25, 0.03869),
    (5, 26, 0.12486),
    (5, 27, 0.11493),
    (5, 28, 0.20371),
    (6, 1, 0.26855),
    (6, 2, 0.13711),
    (6, 3, 0.10933),
    (6, 4, 0.15369),
    (6, 5, 0.0433),
    (6, 7, 0.13648),
    (6, 8, 0.212),
    (6, 9, 0.17843),
    (6, 10, 0.16508),
    (6, 11, 0.12289),
    (6, 12, 0.02324),
    (6, 13, 0.13798),
    (6, 14, 0.2022),
    (6, 15, 0.17189),
    (6, 16, 0.04842),
    (6, 17, 0.25797),
    (6, 18, 0.17123),
    (6, 19, 0.11444),
    (6, 20, 0.08078),
    (6, 21, 0.13703),
    (6, 22, 0.30714),
    (6, 23, 0.11809),
    (6, 24, 0.04872),
    (6, 25, 0.02877),
    (6, 26, 0.14563),
    (6, 27, 0.12909),
    (6, 28, 0.19507),
    (7, 1, 0.15905),
    (7, 2, 0.01854),
    (7, 3, 0.1879),
    (7, 4, 0.25081),
    (7, 5, 0.12064),
    (7, 6, 0.13647),
    (7, 8, 0.24055),
    (7, 9, 0.08531),
    (7, 10, 0.26304),
    (7, 11, 0.02398),
    (7, 12, 0.12007),
    (7, 13, 0.04679),
    (7, 14, 0.27218),
    (7, 15, 0.28384),
    (7, 16, 0.11199),
    (7, 17, 0.18163),
    (7, 18, 0.07919),
    (7, 19, 0.02461),
    (7, 20, 0.17972),
    (7, 21, 0.04868),
    (7, 22, 0.17716),
    (7, 23, 0.0181),
    (7, 24, 0.15285),
    (7, 25, 0.1217),
    (7, 26, 0.01546),
    (7, 27, 0.01915),
    (7, 28, 0.27608),
    (8, 1, 0.07997),
    (8, 2, 0.23819),
    (8, 3, 0.30697),
    (8, 4, 0.1839),
    (8, 5, 0.22719),
    (8, 6, 0.21202),
    (8, 7, 0.24064),
    (8, 9, 0.28651),
    (8, 10, 0.2959),
    (8, 11, 0.23101),
    (8, 12, 0.24082),
    (8, 13, 0.1821),
    (8, 14, 0.03589),
    (8, 15, 0.10587),
    (8, 16, 0.33276),
    (8, 17, 0.36947),
    (8, 18, 0.21415),
    (8, 19, 0.18468),
    (8, 20, 0.28895),
    (8, 21, 0.23039),
    (8, 22, 0.06189),
    (8, 23, 0.23534),
    (8, 24, 0.17807),
    (8, 25, 0.23317),
    (8, 26, 0.20799),
    (8, 27, 0.16366),
    (8, 28, 0.14132),
    (9, 1, 0.20016),
    (9, 2, 0.06599),
    (9, 3, 0.2348),
    (9, 4, 0.29459),
    (9, 5, 0.16944),
    (9, 6, 0.17838),
    (9, 7, 0.0855),
    (9, 8, 0.28613),
    (9, 10, 0.28104),
    (9, 11, 0.07311),
    (9, 12, 0.17345),
    (9, 13, 0.0951),
    (9, 14, 0.25639),
    (9, 15, 0.31685),
    (9, 16, 0.15993),
    (9, 17, 0.22366),
    (9, 18, 0.11884),
    (9, 19, 0.07304),
    (9, 20, 0.2224),
    (9, 21, 0.09695),
    (9, 22, 0.2223),
    (9, 23, 0.07904),
    (9, 24, 0.20375),
    (9, 25, 0.1649),
    (9, 26, 0.09686),
    (9, 27, 0.06866),
    (9, 28, 0.32397),
    (10, 1, 0.41211),
    (10, 2, 0.23575),
    (10, 3, 0.108),
    (10, 4, 0.29297),
    (10, 5, 0.15655),
    (10, 6, 0.16458),
    (10, 7, 0.26322),
    (10, 8, 0.29578),
    (10, 9, 0.28095),
    (10, 11, 0.21251),
    (10, 12, 0.14263),
    (10, 13, 0.24042),
    (10, 14, 0.34008),
    (10, 15, 0.32347),
    (10, 16, 0.16229),
    (10, 17, 0.34705),
    (10, 18, 0.29246),
    (10, 19, 0.23398),
    (10, 20, 0.18659),
    (10, 21, 0.19527),
    (10, 22, 0.36562),
    (10, 23, 0.20958),
    (10, 24, 0.19862),
    (10, 25, 0.14759),
    (10, 26, 0.24418),
    (10, 27, 0.21465),
    (10, 28, 0.34728),
    (11, 1, 0.15267),
    (11, 2, 0.02078),
    (11, 3, 0.17453),
    (11, 4, 0.22042),
    (11, 5, 0.11542),
    (11, 6, 0.12316),
    (11, 7, 0.02428),
    (11, 8, 0.23113),
    (11, 9, 0.07276),
    (11, 10, 0.21259),
    (11, 12, 0.10897),
    (11, 13, 0.04341),
    (11, 14, 0.24087),
    (11, 15, 0.27089),
    (11, 16, 0.10307),
    (11, 17, 0.16405),
    (11, 18, 0.05674),
    (11, 19, 0.01553),
    (11, 20, 0.16967),
    (11, 21, 0.03105),
    (11, 22, 0.14535),
    (11, 23, 0.00685),
    (11, 24, 0.14695),
    (11, 25, 0.11533),
    (11, 26, 0.03783),
    (11, 27, 0.01548),
    (11, 28, 0.27051),
    (12, 1, 0.2278),
    (12, 2, 0.11771),
    (12, 3, 0.07645),
    (12, 4, 0.14998),
    (12, 5, 0.01885),
    (12, 6, 0.02339),
    (12, 7, 0.11998),
    (12, 8, 0.24048),
    (12, 9, 0.17363),
    (12, 10, 0.14222),
    (12, 11, 0.10865),
    (12, 13, 0.1157),
    (12, 14, 0.20255),
    (12, 15, 0.18099),
    (12, 16, 0.03193),
    (12, 17, 0.23528),
    (12, 18, 0.15896),
    (12, 19, 0.10246),
    (12, 20, 0.06655),
    (12, 21, 0.11542),
    (12, 22, 0.24328),
    (12, 23, 0.10524),
    (12, 24, 0.06579),
    (12, 25, 0.0268),
    (12, 26, 0.13058),
    (12, 27, 0.11279),
    (12, 28, 0.21464),
    (13, 1, 0.20491),
    (13, 2, 0.0428),
    (13, 3, 0.18062),
    (13, 4, 0.25328),
    (13, 5, 0.12482),
    (13, 6, 0.13778),
    (13, 7, 0.04672),
    (13, 8, 0.18196),
    (13, 9, 0.09526),
    (13, 10, 0.24015),
    (13, 11, 0.04318),
    (13, 12, 0.1158),
    (13, 14, 0.22727),
    (13, 15, 0.26136),
    (13, 16, 0.11027),
    (13, 17, 0.18461),
    (13, 18, 0.10377),
    (13, 19, 0.02747),
    (13, 20, 0.17932),
    (13, 21, 0.05283),
    (13, 22, 0.19675),
    (13, 23, 0.03274),
    (13, 24, 0.15729),
    (13, 25, 0.13068),
    (13, 26, 0.05432),
    (13, 27, 0.04081),
    (13, 28, 0.28778),
    (14, 1, 0.26208),
    (14, 2, 0.19041),
    (14, 3, 0.26689),
    (14, 4, 0.04907),
    (14, 5, 0.1878),
    (14, 6, 0.20222),
    (14, 7, 0.27244),
    (14, 8, 0.03593),
    (14, 9, 0.25637),
    (14, 10, 0.34009),
    (14, 11, 0.24113),
    (14, 12, 0.20246),
    (14, 13, 0.22696),
    (14, 15, 0.06176),
    (14, 16, 0.19357),
    (14, 17, 0.32261),
    (14, 18, 0.30609),
    (14, 19, 0.19036),
    (14, 20, 0.26411),
    (14, 21, 0.25482),
    (14, 22, 0.24251),
    (14, 23, 0.24142),
    (14, 24, 0.14839),
    (14, 25, 0.19479),
    (14, 26, 0.31227),
    (14, 27, 0.29766),
    (14, 28, 0.13966),
    (15, 1, 0.16108),
    (15, 2, 0.27093),
    (15, 3, 0.25751),
    (15, 4, 0.13877),
    (15, 5, 0.18177),
    (15, 6, 0.17219),
    (15, 7, 0.28405),
    (15, 8, 0.10581),
    (15, 9, 0.31684),
    (15, 10, 0.32365),
    (15, 11, 0.27081),
    (15, 12, 0.18099),
    (15, 13, 0.26143),
    (15, 14, 0.06165),
    (15, 16, 0.20348),
    (15, 17, 0.40113),
    (15, 18, 0.33683),
    (15, 19, 0.25231),
    (15, 20, 0.24753),
    (15, 21, 0.26365),
    (15, 22, 0.13544),
    (15, 23, 0.26676),
    (15, 24, 0.13359),
    (15, 25, 0.19603),
    (15, 26, 0.27523),
    (15, 27, 0.26908),
    (15, 28, 0.18213),
    (16, 1, 0.25763),
    (16, 2, 0.10058),
    (16, 3, 0.10341),
    (16, 4, 0.15409),
    (16, 5, 0.04174),
    (16, 6, 0.04858),
    (16, 7, 0.11238),
    (16, 8, 0.32624),
    (16, 9, 0.15979),
    (16, 10, 0.1623),
    (16, 11, 0.10274),
    (16, 12, 0.03202),
    (16, 13, 0.11035),
    (16, 14, 0.19383),
    (16, 15, 0.20319),
    (16, 17, 0.2421),
    (16, 18, 0.13927),
    (16, 19, 0.09596),
    (16, 20, 0.09418),
    (16, 21, 0.1045),
    (16, 22, 0.28251),
    (16, 23, 0.0922),
    (16, 24, 0.06429),
    (16, 25, 0.0449),
    (16, 26, 0.11785),
    (16, 27, 0.11231),
    (16, 28, 0.21543),
    (17, 1, 0.30366),
    (17, 2, 0.17693),
    (17, 3, 0.29466),
    (17, 4, 0.26388),
    (17, 5, 0.23948),
    (17, 6, 0.25795),
    (17, 7, 0.1815),
    (17, 8, 0.3696),
    (17, 9, 0.22388),
    (17, 10, 0.34747),
    (17, 11, 0.16399),
    (17, 12, 0.23523),
    (17, 13, 0.18455),
    (17, 14, 0.32268),
    (17, 15, 0.40079),
    (17, 16, 0.24168),
    (17, 18, 0.21923),
    (17, 19, 0.1708),
    (17, 20, 0.28651),
    (17, 21, 0.1392),
    (17, 22, 0.44969),
    (17, 23, 0.1773),
    (17, 24, 0.26926),
    (17, 25, 0.23337),
    (17, 26, 0.19898),
    (17, 27, 0.17425),
    (17, 28, 0.3966),
    (18, 1, 0.19221),
    (18, 2, 0.07572),
    (18, 3, 0.22293),
    (18, 4, 0.34175),
    (18, 5, 0.17471),
    (18, 6, 0.17155),
    (18, 7, 0.07923),
    (18, 8, 0.21374),
    (18, 9, 0.1188),
    (18, 10, 0.29306),
    (18, 11, 0.05642),
    (18, 12, 0.15898),
    (18, 13, 0.10361),
    (18, 14, 0.30587),
    (18, 15, 0.33677),
    (18, 16, 0.13933),
    (18, 17, 0.21948),
    (18, 19, 0.07042),
    (18, 20, 0.22708),
    (18, 21, 0.07785),
    (18, 22, 0.20769),
    (18, 23, 0.06878),
    (18, 24, 0.21541),
    (18, 25, 0.16076),
    (18, 26, 0.08287),
    (18, 27, 0.06918),
    (18, 28, 0.3881),
    (19, 1, 0.15521),
    (19, 2, 0.02554),
    (19, 3, 0.17819),
    (19, 4, 0.22374),
    (19, 5, 0.11116),
    (19, 6, 0.11452),
    (19, 7, 0.02487),
    (19, 8, 0.1848),
    (19, 9, 0.07302),
    (19, 10, 0.23404),
    (19, 11, 0.01562),
    (19, 12, 0.10242),
    (19, 13, 0.02732),
    (19, 14, 0.19036),
    (19, 15, 0.25199),
    (19, 16, 0.09572),
    (19, 17, 0.171),
    (19, 18, 0.07045),
    (19, 20, 0.16288),
    (19, 21, 0.03304),
    (19, 22, 0.16519),
    (19, 23, 0.01042),
    (19, 24, 0.14423),
    (19, 25, 0.10891),
    (19, 26, 0.03038),
    (19, 27, 0.02269),
    (19, 28, 0.26572),
    (20, 1, 0.36418),
    (20, 2, 0.16882),
    (20, 3, 0.08137),
    (20, 4, 0.21701),
    (20, 5, 0.09065),
    (20, 6, 0.08051),
    (20, 7, 0.18015),
    (20, 8, 0.28832),
    (20, 9, 0.22246),
    (20, 10, 0.18616),
    (20, 11, 0.16951),
    (20, 12, 0.06658),
    (20, 13, 0.1792),
    (20, 14, 0.2637),
    (20, 15, 0.2471),
    (20, 16, 0.09428),
    (20, 17, 0.28655),
    (20, 18, 0.22759),
    (20, 19, 0.1627),
    (20, 21, 0.18416),
    (20, 22, 0.31596),
    (20, 23, 0.17108),
    (20, 24, 0.12156),
    (20, 25, 0.06117),
    (20, 26, 0.19934),
    (20, 27, 0.17456),
    (20, 28, 0.27189),
    (21, 1, 0.14301),
    (21, 2, 0.03534),
    (21, 3, 0.18934),
    (21, 4, 0.25454),
    (21, 5, 0.10883),
    (21, 6, 0.13725),
    (21, 7, 0.0487),
    (21, 8, 0.22997),
    (21, 9, 0.09677),
    (21, 10, 0.19532),
    (21, 11, 0.03103),
    (21, 12, 0.11557),
    (21, 13, 0.05286),
    (21, 14, 0.25479),
    (21, 15, 0.26325),
    (21, 16, 0.10438),
    (21, 17, 0.13949),
    (21, 18, 0.07777),
    (21, 19, 0.03304),
    (21, 20, 0.18417),
    (21, 22, 0.17506),
    (21, 23, 0.03355),
    (21, 24, 0.13228),
    (21, 25, 0.09637),
    (21, 26, 0.07032),
    (21, 27, 0.03887),
    (21, 28, 0.28715),
    (22, 1, 0.05364),
    (22, 2, 0.19074),
    (22, 3, 0.32848),
    (22, 4, 0.14266),
    (22, 5, 0.28313),
    (22, 6, 0.30679),
    (22, 7, 0.17693),
    (22, 8, 0.06171),
    (22, 9, 0.22266),
    (22, 10, 0.36564),
    (22, 11, 0.14485),
    (22, 12, 0.24313),
    (22, 13, 0.19674),
    (22, 14, 0.24241),
    (22, 15, 0.13512),
    (22, 16, 0.28179),
    (22, 17, 0.45004),
    (22, 18, 0.20845),
    (22, 19, 0.16545),
    (22, 20, 0.3161),
    (22, 21, 0.17469),
    (22, 23, 0.17243),
    (22, 24, 0.26832),
    (22, 25, 0.25624),
    (22, 26, 0.17253),
    (22, 27, 0.1565),
    (22, 28, 0.16009),
    (23, 1, 0.14458),
    (23, 2, 0.01516),
    (23, 3, 0.16639),
    (23, 4, 0.22812),
    (23, 5, 0.10313),
    (23, 6, 0.11808),
    (23, 7, 0.01853),
    (23, 8, 0.23556),
    (23, 9, 0.07909),
    (23, 10, 0.20953),
    (23, 11, 0.00712),
    (23, 12, 0.10492),
    (23, 13, 0.03293),
    (23, 14, 0.24115),
    (23, 15, 0.2662),
    (23, 16, 0.09248),
    (23, 17, 0.17728),
    (23, 18, 0.06886),
    (23, 19, 0.01051),
    (23, 20, 0.17106),
    (23, 21, 0.03379),
    (23, 22, 0.17246),
    (23, 24, 0.14283),
    (23, 25, 0.1097),
    (23, 26, 0.03365),
    (23, 27, 0.01102),
    (23, 28, 0.2619),
    (24, 1, 0.25767),
    (24, 2, 0.15492),
    (24, 3, 0.13286),
    (24, 4, 0.10127),
    (24, 5, 0.04925),
    (24, 6, 0.04865),
    (24, 7, 0.15289),
    (24, 8, 0.17782),
    (24, 9, 0.2041),
    (24, 10, 0.19889),
    (24, 11, 0.14978),
    (24, 12, 0.06578),
    (24, 13, 0.15755),
    (24, 14, 0.14806),
    (24, 15, 0.13329),
    (24, 16, 0.06413),
    (24, 17, 0.26944),
    (24, 18, 0.21535),
    (24, 19, 0.14405),
    (24, 20, 0.12172),
    (24, 21, 0.13257),
    (24, 22, 0.2692),
    (24, 23, 0.14309),
    (24, 25, 0.06856),
    (24, 26, 0.15743),
    (24, 27, 0.14981),
    (24, 28, 0.15796),
    (25, 1, 0.24944),
    (25, 2, 0.11983),
    (25, 3, 0.07396),
    (25, 4, 0.14714),
    (25, 5, 0.0388),
    (25, 6, 0.02878),
    (25, 7, 0.12191),
    (25, 8, 0.23318),
    (25, 9, 0.16531),
    (25, 10, 0.14732),
    (25, 11, 0.1167),
    (25, 12, 0.02674),
    (25, 13, 0.13085),
    (25, 14, 0.19476),
    (25, 15, 0.19565),
    (25, 16, 0.04475),
    (25, 17, 0.23338),
    (25, 18, 0.1606),
    (25, 19, 0.10911),
    (25, 20, 0.06161),
    (25, 21, 0.09629),
    (25, 22, 0.25675),
    (25, 23, 0.10994),
    (25, 24, 0.06935),
    (25, 26, 0.12635),
    (25, 27, 0.11705),
    (25, 28, 0.2242),
    (26, 1, 0.17265),
    (26, 2, 0.03262),
    (26, 3, 0.19581),
    (26, 4, 0.24931),
    (26, 5, 0.12496),
    (26, 6, 0.14552),
    (26, 7, 0.01559),
    (26, 8, 0.20796),
    (26, 9, 0.09684),
    (26, 10, 0.24427),
    (26, 11, 0.03758),
    (26, 12, 0.13052),
    (26, 13, 0.05421),
    (26, 14, 0.31256),
    (26, 15, 0.27519),
    (26, 16, 0.11793),
    (26, 17, 0.19881),
    (26, 18, 0.08282),
    (26, 19, 0.03028),
    (26, 20, 0.19919),
    (26, 21, 0.07011),
    (26, 22, 0.17238),
    (26, 23, 0.03372),
    (26, 24, 0.15741),
    (26, 25, 0.12627),
    (26, 27, 0.02409),
    (26, 28, 0.29532),
    (27, 1, 0.1519),
    (27, 2, 0.00965),
    (27, 3, 0.19256),
    (27, 4, 0.25897),
    (27, 5, 0.11473),
    (27, 6, 0.12853),
    (27, 7, 0.01968),
    (27, 8, 0.16331),
    (27, 9, 0.06866),
    (27, 10, 0.21471),
    (27, 11, 0.01569),
    (27, 12, 0.11273),
    (27, 13, 0.04079),
    (27, 14, 0.29771),
    (27, 15, 0.26931),
    (27, 16, 0.112),
    (27, 17, 0.17423),
    (27, 18, 0.06923),
    (27, 19, 0.02265),
    (27, 20, 0.17471),
    (27, 21, 0.03884),
    (27, 22, 0.1569),
    (27, 23, 0.01183),
    (27, 24, 0.14987),
    (27, 25, 0.11703),
    (27, 26, 0.02459),
    (27, 28, 0.29033),
    (28, 1, 0.17167),
    (28, 2, 0.26716),
    (28, 3, 0.27578),
    (28, 4, 0.12735),
    (28, 5, 0.20349),
    (28, 6, 0.19514),
    (28, 7, 0.27575),
    (28, 8, 0.14106),
    (28, 9, 0.32375),
    (28, 10, 0.34701),
    (28, 11, 0.2703),
    (28, 12, 0.215),
    (28, 13, 0.28783),
    (28, 14, 0.13942),
    (28, 15, 0.18204),
    (28, 16, 0.21486),
    (28, 17, 0.39641),
    (28, 18, 0.38766),
    (28, 19, 0.26544),
    (28, 20, 0.27179),
    (28, 21, 0.28721),
    (28, 22, 0.16034),
    (28, 23, 0.26149),
    (28, 24, 0.15771),
    (28, 25, 0.22461),
    (28, 26, 0.2951),
    (28, 27, 0.2902),
];
/// Query:
/// https://victoria.ch1-obs1.dfinity.network/select/0/vmui/#/?g0.expr=sum+by+%28ic_node%2Cpeer%29+%28%0A++rate%28quic_transport_quinn_path_lost_packets%7Bic_subnet%3D%22uzr34-akd3s-xrdag-3ql62-ocgoh-ld2ao-tamcv-54e7j-krwgb-2gm4z-oqe%22%7D%5B7d%5D%29+%2F%0A++rate%28quic_transport_quinn_path_sent_packets%7Bic_subnet%3D%22uzr34-akd3s-xrdag-3ql62-ocgoh-ld2ao-tamcv-54e7j-krwgb-2gm4z-oqe%22%7D%5B7d%5D%29%0A%29&g0.range_input=13d14h36m59s549ms&g0.end_input=2024-06-23T20%3A59%3A19&g0.tab=1&g0.relative_time=none&g0.tenantID=0
pub static UZR_34_PACKET_LOSS: [(u64, u64, f64); 756] = [
    (1, 2, 0.0015710290841178466),
    (1, 3, 0.000604650481546998),
    (1, 4, 0.0014703598418393934),
    (1, 5, 0.0007645636852995265),
    (1, 6, 0.0007827921817261721),
    (1, 7, 0.0019902801948432267),
    (1, 8, 0.0019507953424840192),
    (1, 9, 0.000988074775733191),
    (1, 10, 0.0006984491507763151),
    (1, 11, 0.0016427282206686166),
    (1, 12, 0.0009642059372918418),
    (1, 13, 0.0013075163248400183),
    (1, 14, 0.0015599121404634652),
    (1, 15, 0.0011273607813663772),
    (1, 16, 0.0012028991616503172),
    (1, 17, 0.0975061595575552),
    (1, 18, 0.00131041713608457),
    (1, 19, 0.001239665622407068),
    (1, 20, 0.0007370694261474166),
    (1, 21, 0.0020727419053953172),
    (1, 22, 0.0018607958592351036),
    (1, 23, 0.0019718493476504075),
    (1, 24, 0.0009505221106326554),
    (1, 25, 0.0014192609981996478),
    (1, 26, 0.001587609723452089),
    (1, 27, 0.0013356935725528287),
    (1, 28, 0.002031002900786332),
    (2, 1, 0.0006299699905004875),
    (2, 3, 0.00013533189242899397),
    (2, 4, 0.00000011438971087428629),
    (2, 5, 0.000044206067614898276),
    (2, 6, 0.0000005736245372714264),
    (2, 7, 0.001654012644559191),
    (2, 8, 0.00005991713017929094),
    (2, 9, 0.00012760702158703233),
    (2, 10, 0.00003454325298879739),
    (2, 11, 0.0010119560696488753),
    (2, 12, 0.000003860380483642092),
    (2, 13, 0.0003874051359251012),
    (2, 14, 0.00012254970778005666),
    (2, 15, 0.000014474389872301573),
    (2, 16, 0.000021598332252488958),
    (2, 17, 0.000014071919176387732),
    (2, 18, 0.00006788097956577143),
    (2, 19, 0.0009467080961604346),
    (2, 20, 0.0000034551428592159425),
    (2, 21, 0.0006365569121142126),
    (2, 22, 0.000013720185690607278),
    (2, 23, 0.0009515506184657327),
    (2, 24, 0.0000001155634898879635),
    (2, 25, 0.000012961621321457759),
    (2, 26, 0.0002508911448399392),
    (2, 27, 0.001533069017587888),
    (2, 28, 0.00002987136513638008),
    (3, 1, 0.0024105731938491586),
    (3, 2, 0.001155224066915176),
    (3, 4, 0.0012350839067747637),
    (3, 5, 0.0011108114424246628),
    (3, 6, 0.0007591538025419654),
    (3, 7, 0.0014485932538217375),
    (3, 8, 0.0010673790609745533),
    (3, 9, 0.0011020092543966656),
    (3, 10, 0.0010681231225034592),
    (3, 11, 0.0017843992066371554),
    (3, 12, 0.000826712717114725),
    (3, 13, 0.0011705014705693999),
    (3, 14, 0.0005679934439558889),
    (3, 15, 0.0005394545228643095),
    (3, 16, 0.0008510979717936381),
    (3, 17, 0.0008305881366017883),
    (3, 18, 0.0018428209686202999),
    (3, 19, 0.0010708931001663308),
    (3, 20, 0.0008568606422368447),
    (3, 21, 0.0011539075793907487),
    (3, 22, 0.0008146667476562476),
    (3, 23, 0.000983759853872718),
    (3, 24, 0.000791602468637129),
    (3, 25, 0.0009388869190463222),
    (3, 26, 0.0007889953424715974),
    (3, 27, 0.0011703159279883174),
    (3, 28, 0.0010793316265801814),
    (4, 1, 0.0008241536247009148),
    (4, 2, 0.00005163297701938024),
    (4, 3, 0.00009186924157381814),
    (4, 5, 0.000002061347534949002),
    (4, 6, 0.00017068529050740032),
    (4, 7, 0.000003432345859265298),
    (4, 8, 0.00013533590954225338),
    (4, 9, 0.00015686060945001388),
    (4, 10, 0.000009609016081904011),
    (4, 11, 0.0000005832565476088406),
    (4, 12, 0.000017311350995143012),
    (4, 13, 0.00008198576033116657),
    (4, 14, 0.000028404666382905838),
    (4, 15, 0.000009299642893712882),
    (4, 16, 0.000010397570757779578),
    (4, 17, 0.000010347269956267763),
    (4, 18, 0.0003584604543556271),
    (4, 19, 0.00015208814126547974),
    (4, 20, 0.00000382071270880195),
    (4, 21, 0.000018943484885062713),
    (4, 22, 0.00047594337409992876),
    (4, 23, 0.00002248972631046418),
    (4, 24, 0.000016483939964599623),
    (4, 25, 0.00006527388233936098),
    (4, 26, 0.00017684421725775034),
    (4, 27, 0.000469181539767668),
    (4, 28, 0.00001745048228629689),
    (5, 1, 0.0009297826457148137),
    (5, 2, 0.000754096505569021),
    (5, 3, 0.001705717916583793),
    (5, 4, 0.0013699406048757728),
    (5, 6, 0.00126945168136964),
    (5, 7, 0.0009884404955727059),
    (5, 8, 0.0004475085646825392),
    (5, 9, 0.0009809562567670328),
    (5, 10, 0.0007255336771684141),
    (5, 11, 0.001189942247228348),
    (5, 12, 0.0010153924308476262),
    (5, 13, 0.000995838820433768),
    (5, 14, 0.0007533338729176936),
    (5, 15, 0.00035776635608864384),
    (5, 16, 0.000886527227560073),
    (5, 17, 0.0003426645661294138),
    (5, 18, 0.0010997621474606136),
    (5, 19, 0.001484414379205527),
    (5, 20, 0.001387590916836805),
    (5, 21, 0.0009267579013499254),
    (5, 22, 0.0007974113133378478),
    (5, 23, 0.001018396948846605),
    (5, 24, 0.0014332169285905122),
    (5, 25, 0.0011621209158384274),
    (5, 26, 0.00046817554399815125),
    (5, 27, 0.0009047557108903465),
    (5, 28, 0.000945632014810462),
    (6, 1, 0.0010303091797243039),
    (6, 2, 0.0010840055537068697),
    (6, 3, 0.0005716697724557826),
    (6, 4, 0.0001802970725323918),
    (6, 5, 0.0002966085737487621),
    (6, 7, 0.00021507605550282572),
    (6, 8, 0.00039132260411478456),
    (6, 9, 0.00038560158165752706),
    (6, 10, 0.00030876768919700187),
    (6, 11, 0.0002893612464406573),
    (6, 12, 0.0007504548990312621),
    (6, 13, 0.00009909396688632878),
    (6, 14, 0.00022141649611925052),
    (6, 15, 0.0013267935909123151),
    (6, 16, 0.00011700818961940225),
    (6, 17, 0.00029433942219866585),
    (6, 18, 0.0003294119380912806),
    (6, 19, 0.00022941317436345432),
    (6, 20, 0.0006564638381008949),
    (6, 21, 0.0003148861759070332),
    (6, 22, 0.0011380100960846585),
    (6, 23, 0.00007263931024158746),
    (6, 24, 0.00024741800650197936),
    (6, 25, 0.0003466369121863593),
    (6, 26, 0.0002782212373637851),
    (6, 27, 0.00013647536974569828),
    (6, 28, 0.00010327262386524211),
    (7, 1, 0.004800713963227138),
    (7, 2, 0.01734732817439863),
    (7, 3, 0.00027923860405468215),
    (7, 4, 0.0008389133978864172),
    (7, 5, 0.0050931015987512205),
    (7, 6, 0.0017338081825906113),
    (7, 8, 0.0005914824880023688),
    (7, 9, 0.00671784220913477),
    (7, 10, 0.0011820104363379688),
    (7, 11, 0.014440811090599295),
    (7, 12, 0.004998380288948411),
    (7, 13, 0.012806599265085254),
    (7, 14, 0.0009106470633901842),
    (7, 15, 0.00019624348986483243),
    (7, 16, 0.0020977972794734004),
    (7, 17, 0.0034594941633231814),
    (7, 18, 0.009452048947340815),
    (7, 19, 0.014201164472833644),
    (7, 20, 0.001977940826365158),
    (7, 21, 0.012503746353249624),
    (7, 22, 0.0042058172463707725),
    (7, 23, 0.01723828073374927),
    (7, 24, 0.004541998497506897),
    (7, 25, 0.0037692822174683685),
    (7, 26, 0.016348860434057557),
    (7, 27, 0.015841490399907034),
    (7, 28, 0.0014205177289877576),
    (8, 1, 0.07731779039468933),
    (8, 2, 0.000030043962803280617),
    (8, 3, 0.0007867550805162683),
    (8, 4, 0.000007361183604711801),
    (8, 5, 0.00026934840752414056),
    (8, 6, 0.00011466765924442852),
    (8, 7, 0.0000006984880759936401),
    (8, 9, 0.00009850133022451113),
    (8, 10, 0.00003617189110868672),
    (8, 11, 0.00000034429689409771837),
    (8, 12, 0.00007345878806794766),
    (8, 13, 0.00006028863355238967),
    (8, 14, 0.00005355715283824861),
    (8, 15, 0.0000003039381263025015),
    (8, 16, 0.0000073237274703833694),
    (8, 17, 0.00006802028182338702),
    (8, 18, 0.00000011369663577339577),
    (8, 19, 0.000010143830396979373),
    (8, 20, 0.00006268724940196939),
    (8, 21, 0.000013724368182831268),
    (8, 22, 0.00040129779260917936),
    (8, 23, 0.0000012556597436056953),
    (8, 24, 0.000006878251453763549),
    (8, 25, 0.000005167146273528744),
    (8, 26, 0.00018858396111543787),
    (8, 27, 0.00000043698520411797376),
    (8, 28, 0.000018089403901333876),
    (9, 1, 0.22960451403775473),
    (9, 2, 0.000007747978907418754),
    (9, 3, 0.00020586679088977554),
    (9, 4, 0.000031567850975603275),
    (9, 5, 0.000010963230594014378),
    (9, 6, 0.00005543349686022829),
    (9, 7, 0.000010992106897799898),
    (9, 8, 0.00006420183477930649),
    (9, 10, 0.000029673408919318693),
    (9, 11, 0.0007912914486966885),
    (9, 12, 0.000019710452303010742),
    (9, 13, 0.00002239840079853625),
    (9, 14, 0.0002350591267681064),
    (9, 15, 0.00002464973219206159),
    (9, 16, 0.000008295538705370577),
    (9, 17, 0.0000245771234750068),
    (9, 18, 0.000013341938506779288),
    (9, 19, 0.000014375287303086934),
    (9, 20, 0.00001466463255511477),
    (9, 21, 0.0000267282790011686),
    (9, 22, 0.000052019140269264944),
    (9, 23, 0.000007921251045496627),
    (9, 24, 0.000027480575101467406),
    (9, 25, 0.000012898415648449996),
    (9, 26, 0.0002026181298346616),
    (9, 27, 0.0005335099337748344),
    (9, 28, 0.00003351903501617965),
    (10, 1, 0.0006552199467518942),
    (10, 2, 0.0003806452017454406),
    (10, 3, 0.0017899351155395253),
    (10, 4, 0.0002831603678918274),
    (10, 5, 0.0008316404942241271),
    (10, 6, 0.0006841491922498615),
    (10, 7, 0.0003163731203427206),
    (10, 8, 0.0014804434563031616),
    (10, 9, 0.0002189383156136075),
    (10, 11, 0.00073114469189755),
    (10, 12, 0.0009040500263339646),
    (10, 13, 0.0009872960805936881),
    (10, 14, 0.00005482822164544929),
    (10, 15, 0.00010422184320296438),
    (10, 16, 0.000505684304864019),
    (10, 17, 0.00004785941489012363),
    (10, 18, 0.00028297235934836767),
    (10, 19, 0.00035610764605542973),
    (10, 20, 0.0006422464032869675),
    (10, 21, 0.0007133696038036759),
    (10, 22, 0.00008012992360083137),
    (10, 23, 0.00028301124423674964),
    (10, 24, 0.0006050758613135959),
    (10, 25, 0.0007456658888302926),
    (10, 26, 0.0005336955658235308),
    (10, 27, 0.0008041179230039985),
    (10, 28, 0.00014617946914056225),
    (11, 1, 0.07694798520393115),
    (11, 2, 0.0011536219343932597),
    (11, 3, 0.0006930132235429352),
    (11, 4, 0.00003518473145224688),
    (11, 5, 0.00005441904207489469),
    (11, 6, 0.0002782279503501092),
    (11, 7, 0.0008956822368490377),
    (11, 8, 0.000041703010371632396),
    (11, 9, 0.00008078225356696812),
    (11, 10, 0.0019417893882419204),
    (11, 12, 0.00001133581209757867),
    (11, 13, 0.0003621606965478868),
    (11, 14, 0.0001064775818905934),
    (11, 15, 0.000016005671808533493),
    (11, 16, 0.000021597988403438844),
    (11, 17, 0.00001300892321635785),
    (11, 18, 0.00044351726291701275),
    (11, 19, 0.0018414373680661694),
    (11, 20, 0.00005099505095895334),
    (11, 21, 0.0008515684622937062),
    (11, 22, 0.0006703326990975135),
    (11, 23, 0.002310000438505125),
    (11, 24, 0.000003805096938880227),
    (11, 25, 0.00000472411664923805),
    (11, 26, 0.0002498189419539831),
    (11, 27, 0.0013832411869911649),
    (11, 28, 0.00002242115342691808),
    (12, 1, 0.08609007015973384),
    (12, 2, 0.000004755575856077252),
    (12, 3, 0.0015591807861373925),
    (12, 4, 0.000291910469435407),
    (12, 5, 0.00147997853800281),
    (12, 6, 0.0009611189307395313),
    (12, 7, 0.0000012558115533749592),
    (12, 8, 0.0071935296348727765),
    (12, 9, 0.0001813993143105919),
    (12, 10, 0.000038828271135108385),
    (12, 11, 0.0000024769020440408945),
    (12, 13, 0.0005426563111166247),
    (12, 14, 0.000010850623050855831),
    (12, 15, 0.00013468031847119048),
    (12, 16, 0.0005828421001495896),
    (12, 17, 0.000026278372005015996),
    (12, 18, 0.00026550146646997166),
    (12, 19, 0.000006783260913683006),
    (12, 20, 0.0002336904565887005),
    (12, 21, 0.000034891331282078635),
    (12, 22, 0.000026877452709919164),
    (12, 23, 0.000002013252120234101),
    (12, 24, 0.0001442076538481726),
    (12, 25, 0.0006868237115695929),
    (12, 26, 0.00031191690453081974),
    (12, 27, 0.0000018852380207263066),
    (12, 28, 0.0001163949179799989),
    (13, 1, 0.0010478725224717204),
    (13, 2, 0.0001811297811543761),
    (13, 3, 0.000030339604357820484),
    (13, 4, 0.000048057540895632365),
    (13, 5, 0.00002686501507413143),
    (13, 6, 0.00030657118650618837),
    (13, 7, 0.0001632388847805358),
    (13, 8, 0.00006553083727758599),
    (13, 9, 0.00009975655627495924),
    (13, 10, 0.0004067415239148866),
    (13, 11, 0.00024051859484388666),
    (13, 12, 0.000022997433350492667),
    (13, 14, 0.0003048043766446395),
    (13, 15, 0.00016317062079179912),
    (13, 16, 0.00002091182568263829),
    (13, 17, 0.00001583555252612317),
    (13, 18, 0.00006269925908509465),
    (13, 19, 0.000518862300569203),
    (13, 20, 0.000017315963344183517),
    (13, 21, 0.00009895756548657733),
    (13, 22, 0.0000360974983049745),
    (13, 23, 0.0003187696178277907),
    (13, 24, 0.0000017296794661794043),
    (13, 25, 0.00027224499527726576),
    (13, 26, 0.00026333603166200806),
    (13, 27, 0.0002144639371614338),
    (13, 28, 0.00004915054006776485),
    (14, 1, 0.0007196754691847787),
    (14, 2, 0.00003792338383179237),
    (14, 3, 0.0023626089749827273),
    (14, 4, 0.00011795196112270625),
    (14, 5, 0.00003595780351757213),
    (14, 6, 0.000009689154617799184),
    (14, 7, 0.00024046086567088639),
    (14, 8, 0.0009077401818582502),
    (14, 9, 0.00015884561330348643),
    (14, 10, 0.00014563084862235186),
    (14, 11, 0.000022183257633450588),
    (14, 12, 0.00002344450068814806),
    (14, 13, 0.000054118411083450584),
    (14, 15, 0.00018311657756226333),
    (14, 16, 0.00001548301697909238),
    (14, 17, 0.0004472169346145907),
    (14, 18, 0.00008161395119300496),
    (14, 19, 0.0007883062346680398),
    (14, 20, 0.000012721686960455908),
    (14, 21, 0.00004804005148159056),
    (14, 22, 0.00004975554285940164),
    (14, 23, 0.00009917369858160856),
    (14, 24, 0.0007500317016005083),
    (14, 25, 0.0007330298907274315),
    (14, 26, 0.00021645620711526265),
    (14, 27, 0.000003695029365668535),
    (14, 28, 0.0000464556994410504),
    (15, 1, 0.08565491764411137),
    (15, 2, 0.0016382147050645413),
    (15, 3, 0.001280872312954657),
    (15, 4, 0.0024002284604199087),
    (15, 5, 0.0023141617152935526),
    (15, 6, 0.0024997309770251747),
    (15, 7, 0.0014887662142611334),
    (15, 8, 0.0018722644518471634),
    (15, 9, 0.0010758970358982704),
    (15, 10, 0.0011846579832743252),
    (15, 11, 0.0020017696036541558),
    (15, 12, 0.002105872602622769),
    (15, 13, 0.0015220541934023672),
    (15, 14, 0.0005025723757716746),
    (15, 16, 0.002071864826895407),
    (15, 17, 0.0009313324927949498),
    (15, 18, 0.0011397329535888017),
    (15, 19, 0.001626598783220717),
    (15, 20, 0.001709881554345757),
    (15, 21, 0.001552458400633426),
    (15, 22, 0.0022813942297733917),
    (15, 23, 0.0015291280759536505),
    (15, 24, 0.0022718910813773214),
    (15, 25, 0.0021203194493266196),
    (15, 26, 0.0011991528313378321),
    (15, 27, 0.002007633736013893),
    (15, 28, 0.0020955517354032775),
    (16, 1, 0.0017116040559667727),
    (16, 2, 0.000012658982664189503),
    (16, 3, 0.000874847056059203),
    (16, 4, 0.00004912539696398208),
    (16, 5, 0.0009951606343406969),
    (16, 6, 0.0006651034323930541),
    (16, 7, 0.0000015894727855011016),
    (16, 8, 0.017785305332384937),
    (16, 9, 0.00007303659880043129),
    (16, 10, 0.00004455327161947505),
    (16, 11, 0.0000014558849501476996),
    (16, 12, 0.000827960437794219),
    (16, 13, 0.00005986612943192219),
    (16, 14, 0.000013651610213209229),
    (16, 15, 0.00001405162864186783),
    (16, 17, 0.000032225252674753513),
    (16, 18, 0.0025995849338900723),
    (16, 19, 0.00010678351950105097),
    (16, 20, 0.000119887049976039),
    (16, 21, 0.00003997638757327403),
    (16, 22, 0.0012285189003978592),
    (16, 23, 0.00000651323616541721),
    (16, 24, 0.00021196257628188064),
    (16, 25, 0.0004053090494775421),
    (16, 26, 0.00017714535438813315),
    (16, 27, 0.000002772539218953522),
    (16, 28, 0.00009671294709709575),
    (17, 1, 0.0004071643612268507),
    (17, 2, 0.00002498478542775754),
    (17, 3, 0.00020207493589138056),
    (17, 4, 0.000027356488493550596),
    (17, 5, 0.0003964157862248368),
    (17, 6, 0.00001753222649639585),
    (17, 7, 0.00005286974266971568),
    (17, 8, 0.0002081757928917753),
    (17, 9, 0.00008186801204261038),
    (17, 10, 0.0004226181134169776),
    (17, 11, 0.0004091338195361863),
    (17, 12, 0.000027212214045949035),
    (17, 13, 0.00004516292817336791),
    (17, 14, 0.00009725115198410032),
    (17, 15, 0.0000255605632431957),
    (17, 16, 0.000015483125314246326),
    (17, 18, 0.00001892230836838507),
    (17, 19, 0.00002166105544940609),
    (17, 20, 0.00006767633704446603),
    (17, 21, 0.000043398127337076295),
    (17, 22, 0.00006686977858981775),
    (17, 23, 0.00001709161220410873),
    (17, 24, 0.00002533431122225152),
    (17, 25, 0.000020442691122320003),
    (17, 26, 0.00036293733251058235),
    (17, 27, 0.000015143609603251195),
    (17, 28, 0.0000735870921096062),
    (18, 1, 0.0008704021832028811),
    (18, 2, 0.0000026141600992248035),
    (18, 3, 0.0010058976459524623),
    (18, 4, 0.00003637613483047555),
    (18, 5, 0.00005811718212136656),
    (18, 6, 0.0000937722151187934),
    (18, 7, 0.000001536458739168789),
    (18, 8, 0.00003615315546135844),
    (18, 9, 0.00010816009860050532),
    (18, 10, 0.00017356625307371368),
    (18, 11, 0.0000002149278111214396),
    (18, 12, 0.000004278552748311012),
    (18, 13, 0.000012556678830201863),
    (18, 14, 0.0001633979277959071),
    (18, 15, 0.000013129140192302517),
    (18, 16, 0.000016296710302447435),
    (18, 17, 0.000008524035591765043),
    (18, 19, 0.00001142504844867243),
    (18, 20, 0.00001681991542946522),
    (18, 21, 0.00001717000006398758),
    (18, 22, 0.00008742870787857062),
    (18, 23, 0.00008742870787857062),
    (18, 24, 0.00008742870787857062),
    (18, 25, 0.00040389672128712134),
    (18, 26, 0.00019327961156865146),
    (18, 27, 0.000000638368092830637),
    (18, 28, 0.000010867788159403047),
    (19, 1, 0.005478670048921076),
    (19, 2, 0.004922357899458266),
    (19, 3, 0.003505344749440934),
    (19, 4, 0.004516308370787043),
    (19, 5, 0.004354292040406406),
    (19, 6, 0.004884505089339174),
    (19, 7, 0.004886767887767295),
    (19, 8, 0.004815830330834222),
    (19, 9, 0.0035521223119790576),
    (19, 10, 0.003421229311742545),
    (19, 11, 0.005411281535548319),
    (19, 12, 0.0049460032760590255),
    (19, 13, 0.005763221892422341),
    (19, 14, 0.0048838190477588),
    (19, 15, 0.004750417889491042),
    (19, 16, 0.003877325024165015),
    (19, 17, 0.004615048699779602),
    (19, 18, 0.004966534523625512),
    (19, 20, 0.0046468279128425265),
    (19, 21, 0.004407519957421945),
    (19, 22, 0.0024481754256725245),
    (19, 23, 0.005842016618838598),
    (19, 24, 0.0038532059802309578),
    (19, 25, 0.00476645721215984),
    (19, 26, 0.005397646628138394),
    (19, 27, 0.005139630139656028),
    (19, 28, 0.005101978536665982),
    (20, 1, 0.002116995045904918),
    (20, 2, 0.0005163891843923561),
    (20, 3, 0.0026627864299305776),
    (20, 4, 0.0007873200854191528),
    (20, 5, 0.0011942541299423605),
    (20, 6, 0.0009048791434402978),
    (20, 7, 0.000829715918457058),
    (20, 8, 0.00045517742198916727),
    (20, 9, 0.00038678916528774943),
    (20, 10, 0.0006888131322870254),
    (20, 11, 0.0008737992479435688),
    (20, 12, 0.0017206309590335946),
    (20, 13, 0.0005275504068403083),
    (20, 14, 0.0004127087255153732),
    (20, 15, 0.0001656105921587709),
    (20, 16, 0.0011637094291459243),
    (20, 17, 0.000394809841164519),
    (20, 18, 0.002660364127687724),
    (20, 19, 0.0007382237458984698),
    (20, 21, 0.0005989541312915719),
    (20, 22, 0.00034548192750047786),
    (20, 23, 0.0005018921298594702),
    (20, 24, 0.0008539844575510731),
    (20, 25, 0.002426474710189396),
    (20, 26, 0.0004742200263232498),
    (20, 27, 0.0007211368494179763),
    (20, 28, 0.0003921875495975398),
    (21, 1, 0.005437590993965016),
    (21, 2, 0.007612188752343594),
    (21, 3, 0.00027447112666460175),
    (21, 4, 0.0003883606148179016),
    (21, 5, 0.004062698171539094),
    (21, 6, 0.0019480818002804317),
    (21, 7, 0.007441182472814204),
    (21, 8, 0.0003359692958229987),
    (21, 9, 0.0032435625884562162),
    (21, 10, 0.004071200494723933),
    (21, 11, 0.00879143652744199),
    (21, 12, 0.003657429388261381),
    (21, 13, 0.008482609636129962),
    (21, 14, 0.0013394513669272923),
    (21, 15, 0.00035631893568696964),
    (21, 16, 0.0052367166676140255),
    (21, 17, 0.007084248481434362),
    (21, 18, 0.008835483502920223),
    (21, 19, 0.0070069451764793135),
    (21, 20, 0.0009814264808548252),
    (21, 22, 0.003567136641023579),
    (21, 23, 0.007193739703352084),
    (21, 24, 0.00331759600451774),
    (21, 25, 0.004872778210506175),
    (21, 26, 0.0023202959379060384),
    (21, 27, 0.008036721092606034),
    (21, 28, 0.0006929450703633507),
    (22, 1, 0.001277832481494668),
    (22, 2, 0.0005470599898343964),
    (22, 3, 0.00037197298120356223),
    (22, 4, 0.0009292155846120491),
    (22, 5, 0.0004534379687850775),
    (22, 6, 0.00032927101340643065),
    (22, 7, 0.0005999345967254668),
    (22, 8, 0.0006893398888420688),
    (22, 9, 0.00040376250071012056),
    (22, 10, 0.0002520014551803068),
    (22, 11, 0.0006475970206650325),
    (22, 12, 0.0004385828446827743),
    (22, 13, 0.000596883099949584),
    (22, 14, 0.0006596078740284351),
    (22, 15, 0.0005511602646064695),
    (22, 16, 0.000362959315203679),
    (22, 17, 0.002610415585928723),
    (22, 18, 0.0005213214996101541),
    (22, 19, 0.0006013698567502938),
    (22, 20, 0.00030793792314653197),
    (22, 21, 0.000562984357158547),
    (22, 23, 0.0008178832345354501),
    (22, 24, 0.009657224343272326),
    (22, 25, 0.00040016172052981415),
    (22, 26, 0.0003657855858921889),
    (22, 27, 0.0006408493053434299),
    (22, 28, 0.0008508358128411688),
    (23, 1, 0.0007751098652671235),
    (23, 2, 0.0010586922521105247),
    (23, 3, 0.0015685132004586047),
    (23, 4, 0.000069439916168747),
    (23, 5, 0.000043704728227240934),
    (23, 6, 0.0001251750381062348),
    (23, 7, 0.0013880213755291832),
    (23, 8, 0.00001427573287898589),
    (23, 9, 0.00010665157375676515),
    (23, 10, 0.0020629635981314347),
    (23, 11, 0.0012202391223508477),
    (23, 12, 0.00016903134943693372),
    (23, 13, 0.000384982143370318),
    (23, 14, 0.00014097643676300777),
    (23, 15, 0.000005012376838169228),
    (23, 16, 0.00002414272657948895),
    (23, 17, 0.000020945910448335192),
    (23, 18, 0.00007130448518001824),
    (23, 19, 0.002114341025403396),
    (23, 20, 0.00021201673163459618),
    (23, 21, 0.0003602573377079327),
    (23, 22, 0.000026432394763049293),
    (23, 24, 0.00008742870787857062),
    (23, 25, 0.000007234119938147162),
    (23, 26, 0.00022853526291815364),
    (23, 27, 0.0013668888523745858),
    (23, 28, 0.000020810022658780474),
    (24, 1, 0.0018095872527493632),
    (24, 2, 0.000025907081869283093),
    (24, 3, 0.00018843771762042357),
    (24, 4, 0.000009873026152075568),
    (24, 5, 0.00010229608509294919),
    (24, 6, 0.0002296063898229225),
    (24, 7, 0.000022609446414147656),
    (24, 8, 0.000023174981772876835),
    (24, 9, 0.00009432263585476032),
    (24, 10, 0.00002634163553135411),
    (24, 11, 0.0007759690049563653),
    (24, 12, 0.000026174862538164374),
    (24, 13, 0.00024531027045108866),
    (24, 14, 0.0001615674676972815),
    (24, 15, 0.000026422511297754426),
    (24, 16, 0.00003282337806131517),
    (24, 17, 0.000017548538851709616),
    (24, 18, 0.00018041955748003083),
    (24, 19, 0.00000807887474662629),
    (24, 20, 0.00009460732506399484),
    (24, 21, 0.00001618700135913815),
    (24, 22, 0.0008101514337492992),
    (24, 23, 0.00000648083414816321),
    (24, 25, 0.000022576586088174847),
    (24, 26, 0.00022600424494929644),
    (24, 27, 0.000005155239143524608),
    (24, 28, 0.000005204235600140306),
    (25, 1, 0.0007845664329367326),
    (25, 2, 0.00009784786785645445),
    (25, 3, 0.0004198166292336862),
    (25, 4, 0.000004266318415327669),
    (25, 5, 0.0006000514994834183),
    (25, 6, 0.0010573258272126562),
    (25, 7, 0.00010016458057081247),
    (25, 8, 0.00026024651179375137),
    (25, 9, 0.0005079812707522999),
    (25, 10, 0.00040614564313336157),
    (25, 11, 0.0007735603618184608),
    (25, 12, 0.0011296054568729736),
    (25, 13, 0.00015003006871627957),
    (25, 14, 0.00017812925562819715),
    (25, 15, 0.00013742051256902005),
    (25, 16, 0.00036314337415538833),
    (25, 17, 0.000019667374387224073),
    (25, 18, 0.00028259765691475555),
    (25, 19, 0.000038226942995826576),
    (25, 20, 0.00018452500266952413),
    (25, 21, 0.00003462092445800032),
    (25, 22, 0.000016101562719469438),
    (25, 23, 0.00012811548853377608),
    (25, 24, 0.00004613308459186528),
    (25, 26, 0.00025007874207684305),
    (25, 27, 0.00010394204378800903),
    (25, 28, 0.000047429041617548515),
    (26, 1, 0.0012031809476130682),
    (26, 2, 0.003340954965013561),
    (26, 3, 0.0005684807765189843),
    (26, 4, 0.000505753846111153),
    (26, 5, 0.001554504381887627),
    (26, 6, 0.0006935218442781299),
    (26, 7, 0.004401169791418139),
    (26, 8, 0.00043473599521617114),
    (26, 9, 0.0015099085971913028),
    (26, 10, 0.002380968159835428),
    (26, 11, 0.0024590373118255574),
    (26, 12, 0.0006696534179619972),
    (26, 13, 0.002297346098099401),
    (26, 14, 0.0015454877500032948),
    (26, 15, 0.0005309406324624941),
    (26, 16, 0.0010844947549461558),
    (26, 17, 0.0005844816552409979),
    (26, 18, 0.0013888057545437633),
    (26, 19, 0.0050625929826329736),
    (26, 20, 0.0005462278385994381),
    (26, 21, 0.001684886526356295),
    (26, 22, 0.0006249874618481952),
    (26, 23, 0.0030776512401475085),
    (26, 24, 0.0006033827741730153),
    (26, 25, 0.0009218347329417961),
    (26, 27, 0.004115663262830986),
    (26, 28, 0.0003553006878709591),
    (27, 1, 0.08337176523726189),
    (27, 2, 0.016796330756562523),
    (27, 3, 0.0002389283310260742),
    (27, 4, 0.0014754258204297097),
    (27, 5, 0.0046760100007884105),
    (27, 6, 0.006518089028186626),
    (27, 7, 0.016527527864210582),
    (27, 8, 0.008020499485125076),
    (27, 9, 0.009022383404280793),
    (27, 10, 0.003976351607261761),
    (27, 11, 0.01501264617730465),
    (27, 12, 0.005656803183381575),
    (27, 13, 0.011825822848023512),
    (27, 14, 0.0009902782859318882),
    (27, 15, 0.0011952135184923325),
    (27, 16, 0.005687677524943578),
    (27, 17, 0.003049284388822451),
    (27, 18, 0.01081029689183083),
    (27, 19, 0.0102841082521828),
    (27, 20, 0.003198410985439323),
    (27, 21, 0.012926094970303814),
    (27, 22, 0.005511920659040426),
    (27, 23, 0.013877867074513878),
    (27, 24, 0.002790110495294925),
    (27, 25, 0.005514804582777529),
    (27, 26, 0.010721371559223166),
    (27, 28, 0.000961747496223411),
    (28, 1, 0.0013510727903080972),
    (28, 2, 0.00018665629351707964),
    (28, 3, 0.00019940390665870893),
    (28, 4, 0.0003656153536255705),
    (28, 5, 0.0002006949090159931),
    (28, 6, 0.00020579578745272333),
    (28, 7, 0.0001031800686766537),
    (28, 8, 0.00046100164070842013),
    (28, 9, 0.00018698317174783424),
    (28, 10, 0.00008964449836325932),
    (28, 11, 0.0001138041392324336),
    (28, 12, 0.000225464495074174),
    (28, 13, 0.00013895644524952993),
    (28, 14, 0.0003408235220169582),
    (28, 15, 0.00011883955989146767),
    (28, 16, 0.0001955060768838096),
    (28, 17, 0.00007811113756959626),
    (28, 18, 0.0003853525540376332),
    (28, 19, 0.00007343934705913181),
    (28, 20, 0.000201770269238149),
    (28, 21, 0.00015710235385729565),
    (28, 22, 0.0004367831318372201),
    (28, 23, 0.00011538005702772607),
    (28, 24, 0.000362374942512266),
    (28, 25, 0.00020722976617729423),
    (28, 26, 0.0002848713985860147),
    (28, 27, 0.000141113896654633),
];

const LHG_73_RTT: [(u64, u64, f64); 156] = [
    (1, 2, 0.61712),
    (1, 3, 0.16138),
    (1, 4, 0.1979),
    (1, 5, 0.31523),
    (1, 6, 0.03331),
    (1, 7, 0.0301),
    (1, 8, 0.0968),
    (1, 9, 0.1448),
    (1, 10, 0.26926),
    (1, 11, 0.04916),
    (1, 12, 0.03823),
    (1, 13, 0.31636),
    (2, 1, 0.4457),
    (2, 3, 0.21571),
    (2, 4, 0.31776),
    (2, 5, 0.31094),
    (2, 6, 0.34994),
    (2, 7, 0.24353),
    (2, 8, 0.36381),
    (2, 9, 0.05638),
    (2, 10, 0.21407),
    (2, 11, 0.33622),
    (2, 12, 0.27787),
    (2, 13, 0.03922),
    (3, 1, 0.16143),
    (3, 2, 0.21653),
    (3, 4, 0.13629),
    (3, 5, 0.1642),
    (3, 6, 0.17138),
    (3, 7, 0.13677),
    (3, 8, 0.20414),
    (3, 9, 0.24348),
    (3, 10, 0.14349),
    (3, 11, 0.15612),
    (3, 12, 0.16038),
    (3, 13, 0.16789),
    (4, 1, 0.19735),
    (4, 2, 0.32791),
    (4, 3, 0.13626),
    (4, 5, 0.24396),
    (4, 6, 0.18301),
    (4, 7, 0.16498),
    (4, 8, 0.23006),
    (4, 9, 0.28532),
    (4, 10, 0.32546),
    (4, 11, 0.17209),
    (4, 12, 0.1687),
    (4, 13, 0.3046),
    (5, 1, 0.32781),
    (5, 2, 0.31353),
    (5, 3, 0.16413),
    (5, 4, 0.24397),
    (5, 6, 0.30252),
    (5, 7, 0.28085),
    (5, 8, 0.35983),
    (5, 9, 0.25506),
    (5, 10, 0.03217),
    (5, 11, 0.2806),
    (5, 12, 0.28543),
    (5, 13, 0.39781),
    (6, 1, 0.03333),
    (6, 2, 0.35234),
    (6, 3, 0.17143),
    (6, 4, 0.18291),
    (6, 5, 0.3025),
    (6, 7, 0.02777),
    (6, 8, 0.07972),
    (6, 9, 0.1297),
    (6, 10, 0.25978),
    (6, 11, 0.02073),
    (6, 12, 0.02456),
    (6, 13, 0.33166),
    (7, 1, 0.03004),
    (7, 2, 0.24537),
    (7, 3, 0.13675),
    (7, 4, 0.16501),
    (7, 5, 0.27803),
    (7, 6, 0.02777),
    (7, 8, 0.07466),
    (7, 9, 0.13592),
    (7, 10, 0.23801),
    (7, 11, 0.01887),
    (7, 12, 0.01972),
    (7, 13, 0.29473),
    (8, 1, 0.09677),
    (8, 2, 0.34166),
    (8, 3, 0.20411),
    (8, 4, 0.23096),
    (8, 5, 0.35981),
    (8, 6, 0.0798),
    (8, 7, 0.07474),
    (8, 9, 0.17424),
    (8, 10, 0.30549),
    (8, 11, 0.08596),
    (8, 12, 0.08187),
    (8, 13, 0.27698),
    (9, 1, 0.14482),
    (9, 2, 0.05636),
    (9, 3, 0.24343),
    (9, 4, 0.28514),
    (9, 5, 0.25525),
    (9, 6, 0.12969),
    (9, 7, 0.13586),
    (9, 8, 0.17429),
    (9, 10, 0.25616),
    (9, 11, 0.10919),
    (9, 12, 0.14037),
    (9, 13, 0.23707),
    (10, 1, 0.26862),
    (10, 2, 0.19502),
    (10, 3, 0.16683),
    (10, 4, 0.29872),
    (10, 5, 0.03211),
    (10, 6, 0.25981),
    (10, 7, 0.23806),
    (10, 8, 0.30551),
    (10, 9, 0.25588),
    (10, 11, 0.2647),
    (10, 12, 0.27553),
    (10, 13, 0.05266),
    (11, 1, 0.04922),
    (11, 2, 0.32807),
    (11, 3, 0.15616),
    (11, 4, 0.17251),
    (11, 5, 0.28066),
    (11, 6, 0.02084),
    (11, 7, 0.01885),
    (11, 8, 0.08604),
    (11, 9, 0.10918),
    (11, 10, 0.26476),
    (11, 12, 0.02555),
    (11, 13, 0.2858),
    (12, 1, 0.03829),
    (12, 2, 0.27083),
    (12, 3, 0.16036),
    (12, 4, 0.16875),
    (12, 5, 0.2854),
    (12, 6, 0.02457),
    (12, 7, 0.01961),
    (12, 8, 0.08141),
    (12, 9, 0.1404),
    (12, 10, 0.27557),
    (12, 11, 0.02553),
    (12, 13, 0.30877),
    (13, 1, 0.31634),
    (13, 2, 0.03919),
    (13, 3, 0.16781),
    (13, 4, 0.31543),
    (13, 5, 0.40834),
    (13, 6, 0.32947),
    (13, 7, 0.2947),
    (13, 8, 0.27695),
    (13, 9, 0.23713),
    (13, 10, 0.05268),
    (13, 11, 0.29273),
    (13, 12, 0.30878),
];

const LHG73_PACKET_LOSS: [(u64, u64, f64); 156] = [
    (1, 2, 0.10996749729144095),
    (1, 3, 0.0),
    (1, 4, 0.00014506208657305328),
    (1, 5, 0.00017493731412910373),
    (1, 6, 0.0),
    (1, 7, 0.00021835849005104132),
    (1, 8, 0.000028244598220590316),
    (1, 9, 0.0),
    (1, 10, 0.00017437298381237467),
    (1, 11, 0.0004203211253397596),
    (1, 12, 0.00025079418157498745),
    (1, 13, 0.00017522852720422885),
    (2, 1, 0.46462264150943394),
    (2, 3, 0.0),
    (2, 4, 0.004377136649733218),
    (2, 5, 0.0),
    (2, 6, 0.0038299891540130152),
    (2, 7, 0.5499092558983666),
    (2, 8, 0.13039882959099292),
    (2, 9, 0.0),
    (2, 10, 0.00035081564637782847),
    (2, 11, 0.00006247461968575268),
    (2, 12, 0.00002988196623337816),
    (2, 13, 0.0),
    (3, 1, 0.00011286681715575621),
    (3, 2, 0.0398395352054226),
    (3, 4, 0.0),
    (3, 5, 0.0),
    (3, 6, 0.0),
    (3, 7, 0.0),
    (3, 8, 0.0008279800142755175),
    (3, 9, 0.0),
    (3, 10, 0.00046834536338090247),
    (3, 11, 0.0),
    (3, 12, 0.0),
    (3, 13, 0.0),
    (4, 1, 0.0),
    (4, 2, 0.016789015769439915),
    (4, 3, 0.0),
    (4, 5, 0.0),
    (4, 6, 0.0),
    (4, 7, 0.0),
    (4, 8, 0.000058462437883659755),
    (4, 9, 0.0),
    (4, 10, 0.0009978868278938716),
    (4, 11, 0.0),
    (4, 12, 0.0),
    (4, 13, 0.000029207313511303232),
    (5, 1, 0.0008459496514104023),
    (5, 2, 0.0),
    (5, 3, 0.0),
    (5, 4, 0.0),
    (5, 6, 0.0),
    (5, 7, 0.0),
    (5, 8, 0.0),
    (5, 9, 0.0),
    (5, 10, 0.0),
    (5, 11, 0.0),
    (5, 12, 0.000028875028875028877),
    (5, 13, 0.00707166153564788),
    (6, 1, 0.00016115602589240148),
    (6, 2, 0.022668947818648418),
    (6, 3, 0.0),
    (6, 4, 0.0),
    (6, 5, 0.0),
    (6, 7, 0.0),
    (6, 8, 0.00005460601758313766),
    (6, 9, 0.0),
    (6, 10, 0.0),
    (6, 11, 0.0),
    (6, 12, 0.0),
    (6, 13, 0.0),
    (7, 1, 0.0029997857295907438),
    (7, 2, 0.0033869115958668193),
    (7, 3, 0.0032367831355299198),
    (7, 4, 0.0033353887549750546),
    (7, 5, 0.003399915002124947),
    (7, 6, 0.0025975461478943297),
    (7, 8, 0.0030563669804176134),
    (7, 9, 0.0035285815102328866),
    (7, 10, 0.002148109388339622),
    (7, 11, 0.003549532107131333),
    (7, 12, 0.003492063492063492),
    (7, 13, 0.003373956545766557),
    (8, 1, 0.00011341404632963793),
    (8, 2, 0.021753561762753407),
    (8, 3, 0.0),
    (8, 4, 0.0),
    (8, 5, 0.00023399338968674137),
    (8, 6, 0.0),
    (8, 7, 0.0),
    (8, 9, 0.0),
    (8, 10, 0.0009087977485268681),
    (8, 11, 0.00016970725498515062),
    (8, 12, 0.0),
    (8, 13, 0.0),
    (9, 1, 0.000055850321139346556),
    (9, 2, 0.0),
    (9, 3, 0.0),
    (9, 4, 0.0),
    (9, 5, 0.0),
    (9, 6, 0.0),
    (9, 7, 0.000027785495971103084),
    (9, 8, 0.0003091190108191654),
    (9, 10, 0.0),
    (9, 11, 0.0),
    (9, 12, 0.0),
    (9, 13, 0.000029191114224829965),
    (10, 1, 0.0013883264881124544),
    (10, 2, 0.0),
    (10, 3, 0.0),
    (10, 4, 0.0),
    (10, 5, 0.0),
    (10, 6, 0.0),
    (10, 7, 0.0),
    (10, 8, 0.00002900063801403631),
    (10, 9, 0.0),
    (10, 11, 0.0),
    (10, 12, 0.00014441684478077522),
    (10, 13, 0.0),
    (11, 1, 0.0),
    (11, 2, 0.017175265040440823),
    (11, 3, 0.0),
    (11, 4, 0.0),
    (11, 5, 0.0),
    (11, 6, 0.0),
    (11, 7, 0.0),
    (11, 8, 0.000055944055944055945),
    (11, 9, 0.0),
    (11, 10, 0.0024500510427300573),
    (11, 12, 0.0),
    (11, 13, 0.20009510223490254),
    (12, 1, 0.00005495562333415767),
    (12, 2, 0.008612001832340814),
    (12, 3, 0.00005611672278338946),
    (12, 4, 0.0005651313930488839),
    (12, 5, 0.000028395377232586536),
    (12, 6, 0.00018987685129930016),
    (12, 7, 0.0001321912013536379),
    (12, 8, 0.00005529902950203224),
    (12, 9, 0.00027585445918733276),
    (12, 10, 0.0013517400057520852),
    (12, 11, 0.0),
    (12, 13, 0.00005702554744525548),
    (13, 1, 0.00008762705923589204),
    (13, 2, 0.0),
    (13, 3, 0.0),
    (13, 4, 0.0),
    (13, 5, 0.000240132072639952),
    (13, 6, 0.0),
    (13, 7, 0.0),
    (13, 8, 0.000057097179399337676),
    (13, 9, 0.0),
    (13, 10, 0.0),
    (13, 11, 0.0),
    (13, 12, 0.00002901073397156948),
];

const IO67_RTT: [(u64, u64, f64); 156] = [
    (1, 2, 0.16734),
    (1, 3, 0.27353),
    (1, 4, 0.30555),
    (1, 5, 0.23737),
    (1, 6, 0.25876),
    (1, 7, 0.19405),
    (1, 8, 0.25064),
    (1, 9, 0.18161),
    (1, 10, 0.23736),
    (1, 11, 0.05576),
    (1, 12, 0.2812),
    (1, 13, 0.11474),
    (2, 1, 0.16745),
    (2, 3, 0.12441),
    (2, 4, 0.17481),
    (2, 5, 0.10927),
    (2, 6, 0.12067),
    (2, 7, 0.24545),
    (2, 8, 0.26332),
    (2, 9, 0.04151),
    (2, 10, 0.22915),
    (2, 11, 0.22803),
    (2, 12, 0.13506),
    (2, 13, 0.09143),
    (3, 1, 0.27369),
    (3, 2, 0.12448),
    (3, 4, 0.07763),
    (3, 5, 0.02511),
    (3, 6, 0.01955),
    (3, 7, 0.33227),
    (3, 8, 0.19035),
    (3, 9, 0.10048),
    (3, 10, 0.36291),
    (3, 11, 0.32749),
    (3, 12, 0.00252),
    (3, 13, 0.16926),
    (4, 1, 0.30565),
    (4, 2, 0.17482),
    (4, 3, 0.07763),
    (4, 5, 0.07412),
    (4, 6, 0.06778),
    (4, 7, 0.31882),
    (4, 8, 0.24298),
    (4, 9, 0.14879),
    (4, 10, 0.37033),
    (4, 11, 0.37262),
    (4, 12, 0.07774),
    (4, 13, 0.20558),
    (5, 1, 0.23735),
    (5, 2, 0.10931),
    (5, 3, 0.0251),
    (5, 4, 0.07417),
    (5, 6, 0.0152),
    (5, 7, 0.20899),
    (5, 8, 0.1815),
    (5, 9, 0.08172),
    (5, 10, 0.32365),
    (5, 11, 0.32509),
    (5, 12, 0.02524),
    (5, 13, 0.1358),
    (6, 1, 0.25877),
    (6, 2, 0.1207),
    (6, 3, 0.01956),
    (6, 4, 0.06777),
    (6, 5, 0.01518),
    (6, 7, 0.26372),
    (6, 8, 0.1825),
    (6, 9, 0.09002),
    (6, 10, 0.30955),
    (6, 11, 0.31012),
    (6, 12, 0.02154),
    (6, 13, 0.14768),
    (7, 1, 0.19406),
    (7, 2, 0.24547),
    (7, 3, 0.33227),
    (7, 4, 0.31866),
    (7, 5, 0.20844),
    (7, 6, 0.26364),
    (7, 8, 0.28578),
    (7, 9, 0.33597),
    (7, 10, 0.11232),
    (7, 11, 0.03261),
    (7, 12, 0.33047),
    (7, 13, 0.20231),
    (8, 1, 0.25065),
    (8, 2, 0.26337),
    (8, 3, 0.1903),
    (8, 4, 0.24296),
    (8, 5, 0.18148),
    (8, 6, 0.18248),
    (8, 7, 0.28589),
    (8, 9, 0.25825),
    (8, 10, 0.32082),
    (8, 11, 0.42551),
    (8, 12, 0.1919),
    (8, 13, 0.30328),
    (9, 1, 0.18172),
    (9, 2, 0.04157),
    (9, 3, 0.10048),
    (9, 4, 0.14877),
    (9, 5, 0.08173),
    (9, 6, 0.08999),
    (9, 7, 0.33593),
    (9, 8, 0.25829),
    (9, 10, 0.3733),
    (9, 11, 0.21682),
    (9, 12, 0.10349),
    (9, 13, 0.06968),
    (10, 1, 0.23699),
    (10, 2, 0.22907),
    (10, 3, 0.36289),
    (10, 4, 0.37027),
    (10, 5, 0.32357),
    (10, 6, 0.30947),
    (10, 7, 0.11226),
    (10, 8, 0.32078),
    (10, 9, 0.37328),
    (10, 11, 0.12819),
    (10, 12, 0.36405),
    (10, 13, 0.1937),
    (11, 1, 0.05577),
    (11, 2, 0.22817),
    (11, 3, 0.32739),
    (11, 4, 0.37252),
    (11, 5, 0.32532),
    (11, 6, 0.31036),
    (11, 7, 0.03266),
    (11, 8, 0.42551),
    (11, 9, 0.21658),
    (11, 10, 0.12826),
    (11, 12, 0.33359),
    (11, 13, 0.16365),
    (12, 1, 0.28104),
    (12, 2, 0.13512),
    (12, 3, 0.00253),
    (12, 4, 0.07771),
    (12, 5, 0.02525),
    (12, 6, 0.02147),
    (12, 7, 0.33049),
    (12, 8, 0.1919),
    (12, 9, 0.10349),
    (12, 10, 0.36412),
    (12, 11, 0.33376),
    (12, 13, 0.16952),
    (13, 1, 0.11449),
    (13, 2, 0.09144),
    (13, 3, 0.1693),
    (13, 4, 0.20561),
    (13, 5, 0.13581),
    (13, 6, 0.14766),
    (13, 7, 0.20231),
    (13, 8, 0.3031),
    (13, 9, 0.06971),
    (13, 10, 0.1938),
    (13, 11, 0.16366),
    (13, 12, 0.1695),
];

/// Query for the metric:
/// https://victoria.ch1-obs1.dfinity.network/select/0/vmui/#/?g0.expr=sum+by+%28ic_node%2Cpeer%29+%28%0A++rate%28quic_transport_quinn_path_lost_packets%7Bic_ProductionSubnetTopology%3D%22io67a-2jmkw-zup3h-snbwi-g6a5n-rm5dn-b6png-lvdpl-nqnto-yih6l-gqe%22%7D%5B7d%5D%29+%2F%0A++rate%28quic_transport_quinn_path_sent_packets%7Bic_ProductionSubnetTopology%3D%22io67a-2jmkw-zup3h-snbwi-g6a5n-rm5dn-b6png-lvdpl-nqnto-yih6l-gqe%22%7D%5B7d%5D%29%0A%29&g0.range_input=10d2h52m42s818ms&g0.end_input=2024-05-12T13%3A19%3A31&g0.tab=1&g0.relative_time=none&g0.tenantID=0
const IO67_PACKET_LOSS: [(u64, u64, f64); 156] = [
    (1, 2, 0.0000025116739926176536),
    (1, 3, 0.0004579456767444065),
    (1, 4, 0.001850035700864664),
    (1, 5, 0.000995202969108691),
    (1, 6, 0.00001909138613960752),
    (1, 7, 0.00019945655637087513),
    (1, 8, 0.00020795407398626622),
    (1, 9, 0.000026004830460787808),
    (1, 10, 0.00006330761514513749),
    (1, 11, 0.00009654861405968816),
    (1, 12, 0.0004536072375606995),
    (1, 13, 0.0009260210590594368),
    (2, 1, 0.000026576950863990973),
    (2, 3, 0.0004114995052709546),
    (2, 4, 0.0018229081737066288),
    (2, 5, 0.0000005933958768819974),
    (2, 6, 0.00013024455288572292),
    (2, 7, 0.020455982007400803),
    (2, 8, 0.000031435626028901895),
    (2, 9, 0.000023947440365412273),
    (2, 10, 0.00006601200235208804),
    (2, 11, 0.0006411684186170226),
    (2, 12, 0.00041909322428773237),
    (2, 13, 0.00007295633111814528),
    (3, 1, 0.010389597449360232),
    (3, 2, 0.000005401243077713142),
    (3, 4, 0.0021555313839978565),
    (3, 5, 0.000006727880551439605),
    (3, 6, 0.0011608136729818863),
    (3, 7, 0.0005629997811317654),
    (3, 8, 0.00001949232259855781),
    (3, 9, 0.00101600480987657),
    (3, 10, 0.00005065854264858888),
    (3, 11, 0.005021689441758273),
    (3, 12, 0.0000032934530928022075),
    (3, 13, 0.0000023184022386039645),
    (4, 1, 0.0018678684335336694),
    (4, 2, 0.000031416668268300735),
    (4, 3, 0.0005144044320281668),
    (4, 5, 0.0001028766894281342),
    (4, 6, 0.00019102556100341472),
    (4, 7, 0.0004362537524155629),
    (4, 8, 0.000056674819121417206),
    (4, 9, 0.00015202853894404224),
    (4, 10, 0.0003617712393357278),
    (4, 11, 0.003004178416230635),
    (4, 12, 0.0005811423720677048),
    (4, 13, 0.000051074816581858724),
    (5, 1, 0.0010432149107949453),
    (5, 2, 0.0009475517681796154),
    (5, 3, 0.0022883193286215905),
    (5, 4, 0.002610988212034662),
    (5, 6, 0.001153250918564546),
    (5, 7, 0.0021525973193944293),
    (5, 8, 0.0010767507701540298),
    (5, 9, 0.00043418753932369356),
    (5, 10, 0.001272768969006755),
    (5, 11, 0.010749916709952487),
    (5, 12, 0.0019574384042711),
    (5, 13, 0.0009673222429462834),
    (6, 1, 0.0067117374811837705),
    (6, 2, 0.00006556061456508818),
    (6, 3, 0.0007314081054916355),
    (6, 4, 0.0018472198140076258),
    (6, 5, 0.000006429619908156391),
    (6, 7, 0.0012561006357616922),
    (6, 8, 0.00003722154298823348),
    (6, 9, 0.001102775770117787),
    (6, 10, 0.00003790317704034539),
    (6, 11, 0.00433350243550568),
    (6, 12, 0.0004261915770601068),
    (6, 13, 0.00005815573915253811),
    (7, 1, 0.006823172227417568),
    (7, 2, 0.00008792702682246431),
    (7, 3, 0.001476173624351456),
    (7, 4, 0.030076349208947972),
    (7, 5, 0.037095492354744415),
    (7, 6, 0.030038303242105942),
    (7, 8, 0.0002786281336062296),
    (7, 9, 0.000021040752994576822),
    (7, 10, 0.000001095917541365759),
    (7, 11, 0.00004952133633027111),
    (7, 12, 0.0024578454093489278),
    (7, 13, 0.000016841824481378308),
    (8, 1, 0.00005370160093649248),
    (8, 2, 0.000017874223930090313),
    (8, 3, 0.00006836185034737848),
    (8, 4, 0.0013723956396028574),
    (8, 5, 0.000015717180752751758),
    (8, 6, 0.000017518158418853967),
    (8, 7, 0.00008481692748439206),
    (8, 9, 0.0025713202866593163),
    (8, 10, 0.00004845256158888936),
    (8, 11, 0.00597232779894635),
    (8, 12, 0.000019538842338310524),
    (8, 13, 0.000019167036921761375),
    (9, 1, 0.000017309396411480213),
    (9, 2, 0.000027680298114631145),
    (9, 3, 0.0005667623474787441),
    (9, 4, 0.002033220199129239),
    (9, 5, 0.000004030380786458279),
    (9, 6, 0.00008071943646350249),
    (9, 7, 0.00443521094808668),
    (9, 8, 0.00008616131904608202),
    (9, 10, 0.000029517833129548022),
    (9, 11, 0.000762494536565196),
    (9, 12, 0.00003346306762915821),
    (9, 13, 0.00007681578987797783),
    (10, 1, 0.009322270880568405),
    (10, 2, 0.000020254746844599795),
    (10, 3, 0.00023500601357271062),
    (10, 4, 0.0013617773363115001),
    (10, 5, 0.000009083328382446275),
    (10, 6, 0.00001840239989943796),
    (10, 7, 0.000010781540651193795),
    (10, 8, 0.00002671767220453463),
    (10, 9, 0.000030520812178630785),
    (10, 11, 0.000031855778722983164),
    (10, 12, 0.0004215135278290673),
    (10, 13, 0.00006244122959858073),
    (11, 1, 0.00003363942481658124),
    (11, 2, 0.0000286721370679327),
    (11, 3, 0.0004917590531146349),
    (11, 4, 0.0018349257726532338),
    (11, 5, 0.000024763148915756672),
    (11, 6, 0.00010442346671132577),
    (11, 7, 0.000047054745823687904),
    (11, 8, 0.00038678542449209344),
    (11, 9, 0.00008411905126516441),
    (11, 10, 0.000026530805634556678),
    (11, 12, 0.00048041545797093287),
    (11, 13, 0.0010165654083166037),
    (12, 1, 0.012252953478055162),
    (12, 2, 0.000005131745225463936),
    (12, 3, 0.000008923671744409786),
    (12, 4, 0.0021122113111040983),
    (12, 5, 0.0000015164146296872908),
    (12, 6, 0.0008193443890555587),
    (12, 7, 0.0005300908848447211),
    (12, 8, 0.00012318614018410142),
    (12, 9, 0.001026882749503089),
    (12, 10, 0.000050966344544268),
    (12, 11, 0.004995221578124113),
    (12, 13, 0.000001358177454882406),
    (13, 1, 0.0006337791868513416),
    (13, 2, 0.0000009519790678842553),
    (13, 3, 0.000003302281817464143),
    (13, 4, 0.00148074982778491),
    (13, 5, 0.0000014964488140247861),
    (13, 6, 0.000005996316225352878),
    (13, 7, 0.0011227127562902584),
    (13, 8, 0.00018202700190020091),
    (13, 9, 0.000006003484178758085),
    (13, 10, 0.000007740675111283463),
    (13, 11, 0.0007356809260771047),
    (13, 12, 0.000005987140187701364),
];

/*
Small script to parse text formatted prometheus table data

peer1 peer2 value
peer1 peer3 value
peer2 peer1 value
...


import sys

"""
LATENCY

sum by (ic_node,peer) (quic_transport_quinn_path_rtt_seconds{ic_subnet="<<SUBNET_ID>>"})

PACKETLOSS

sum by (ic_node,peer) (
  rate(quic_transport_quinn_path_lost_packets{ic_subnet="<<SUBNET_ID>>"}[10m]) /
  rate(quic_transport_quinn_path_sent_packets{ic_subnet="<<SUBNET_ID>>"}[10m])
)

"""

def process_data(input_file, output_file):
    # Initialize a dictionary to hold ID to number mapping
    id_to_number = {}
    next_number = 1

    # Read data from the input file
    with open(input_file, 'r') as file:
        data = file.readlines()

    # Prepare to write to the output file
    with open(output_file, 'w') as output:
        # Process each line
        for line in data:
            # Split the line into components
            parts = line.split()
            if len(parts) < 3:
                continue

            node_id, peer_id, value = parts[0], parts[1], parts[2]

            # Assign numbers to node IDs if they haven't been assigned already
            if node_id not in id_to_number:
                id_to_number[node_id] = next_number
                next_number += 1
            if peer_id not in id_to_number:
                id_to_number[peer_id] = next_number
                next_number += 1

            # Map node and peer IDs to their respective numbers
            node_number = id_to_number[node_id]
            peer_number = id_to_number[peer_id]

            # Format the output
            output_line = f"({node_number}, {peer_number}, {value}),\n"
            output.write(output_line)

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: python process_data.py <input_file> <output_file>")
    else:
        input_file = sys.argv[1]
        output_file = sys.argv[2]
        process_data(input_file, output_file)
*/
